<!DOCTYPE html>
<html>
<head>
    <link type="text/css" rel="stylesheet"
          href="{{ url_for('static',filename='/css/plugins/font-awesome-4.7.0/css/font-awesome.min.css') }}">
    <link type="text/css" rel="stylesheet" href="{{ url_for('static',filename='/libs/layui/css/layui.css') }}">
    <link type="text/css" rel="stylesheet" href="{{ url_for('static',filename='/css/admin_main.css') }}">
    <link type="text/css" rel="stylesheet"
          href="{{ url_for('static',filename='/libs/zTree_v3/css/zTreeStyle/zTreeStyle.css') }}">
</head>
<body>
<div class="layui-form timo-compile">
    <form>
        <input type="hidden" name="id" if="${user}" value="${user.id}"/>
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" id="username" name="username" placeholder="请输入用户名"
                       value="{{ user.user_name }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话号码</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" id="phone" name="phone" placeholder="请输入电话号码"
                       value="{{ user.mobile }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份证号</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" id="idcard" name="idcard" placeholder="请输入身份证号"
                       value="{{ user.id_card }}">
            </div>
        </div>

        <div class="layui-form-item" if="!${user}">
            <label class="layui-form-label required">用户密码</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" id="password" name="password" placeholder="请输入用户密码"
                       value="{{ user.pwd }}">
            </div>
        </div>

        <div class="layui-form-item timo-finally">
            <button class="layui-btn" id="save"><i class="fa fa-check-circle"></i> 保存</button>
            <button class="layui-btn btn-secondary close-popup"><i class="fa fa-times-circle"></i> 关闭</button>
        </div>
    </form>
</div>
<script src="{{ url_for('static',filename='/libs/layui/layui.all.js') }}"></script>
<script src="{{ url_for('static',filename='/js/main.js') }}"></script>
<script src="{{ url_for('static',filename='/libs/jquery-3.5.1.min.js') }}"></script>
<script src="{{ url_for('static',filename='/libs/zTree_v3/js/jquery.ztree.core.min.js') }}"></script>
<script src="{{ url_for('static',filename='/js/timoTree.js') }}"></script>
<script type="text/javascript">
    // 树形菜单
    $.fn.selectTree();

    $("#save").click(function (e) {
        e.preventDefault();
        var username = $("#username").val();
        var idcard = $("#idcard").val();
        var phone = $("#phone").val();
        var password = $("#password").val();

        if (username == "") {
            layer.msg("用户名不为空！");
            return false;
        }
        if (idcard == "") {
            layer.msg("身份证不为空！");
            return false;
        }
        if (phone == "") {
            layer.msg("电话不为空！");
            return false;
        }
        if (password == "") {
            layer.msg("密码不为空！");
            return false;
        }
        var id = '{{user.id}}';
        $.ajax({
            url: "/admin/user/update",
            type: "POST",
            data: {
                "id": id,
                "username": username,
                "idcard": idcard,
                "phone": phone,
                "password": password,
            },
            success: function (data) {
                debugger;
                if (data.result == 200) {
                    layer.msg('修改成功······', {
                        icon: 16
                        , shade: 0.01
                        , time: 1000
                    }, function () {
                        layer.closeAll();
                        window.parent.location.reload();
                    });

                } else if (data.result == 300) {
                    layer.msg("该手机号已注册！！");
                    return false;
                }
            },
            error: function (xhr, type, errorThrown) {
                layer.msg("网络有误！")
            }
        })

    })
</script>
</body>
</html>